//获取应用实例
var app = getApp()
var packageId=1;

//获取优惠券信息
 var getVoucherInfo=function(that){
     wx.request({
        url: app.globalData.path+'/weixin/coffee/xcx/user/voucherList',
        data: {
          packageId:packageId,
					userId:that.data.userInfo.userId
        },
        method: 'GET',
        success: function (res) {
          console.info(res.data);  
					that.setData({
						size:res.data.voucherList.length,
						voucherList:res.data.voucherList
					})
        }
      })
			if(packageId == 1){
			that.setData({
				Left:"22.5%"
			})
		}else{
			that.setData({
				Left:"52.5%"
			})
		}
  }

Page({
	data:{
		size:0,
		Left:"",
		userInfo:{},
		wishUser:{},
		voucherList:[],
		ruleHidden:true
	},

	onLoad:function(options){
		var that = this
		if( options.packageId){
         packageId =options.packageId
		}
		if(packageId == 1){
			that.setData({
				Left:"22.5%"
			})
		}else{
			that.setData({
				Left:"52.5%"
			})
		}
		 //调用应用实例的方法获取全局数据
    app.getUserInfo(function(userInfo){
      //更新数据
      that.setData({
        userInfo:userInfo
      })
		   getVoucherInfo(that);
	  })
	},
	toPayOrder:function(){
		wx.redirectTo({
		  url: '../payOrder/payOrder',
		  success: function(res){
			// success
		  },
		  fail: function() {
			// fail
		  },
		  complete: function() {
			// complete
		  }
		})
	},
	//tab切换
	checkTab:function(e){
		packageId = e.currentTarget.dataset.tabnum;
		var that = this
		getVoucherInfo(that);
	},
	showRule:function(){
		this.setData({
			ruleHidden:false
		})
	},
	closeRule:function(){
		this.setData({
			ruleHidden:true
		})
	}







})